<template>
    <el-container class="left-side">
        <el-aside width="200px" class="aside">
            <div class="logo" @click="$router.push('/')">
                <img :src="subStation && subStation.fenzhan_logo" alt="">
            </div>
            <el-menu :default-active="menuActive" class="el-menu-vertical-demo leftMenu" :router="true"
                     unique-opened
                     :collapse="isCollapse">
                <el-submenu :index="index+''" v-for="(item,index) in menu" :key="index">
                    <template slot="title">
                        <i :class="item.icon"></i>
                        <span slot="title">{{item.name}}</span>
                    </template>

                    <el-menu-item :index="mItem.path" v-for="(mItem,mIndex) in item.items" v-if="!mItem.hide"
                                  :key="mItem.name"
                    >
                        {{mItem.name}}
                    </el-menu-item>
                </el-submenu>


            </el-menu>


        </el-aside>
        <el-container>
            <el-header class="header">
                <div class="left">
                    <div class="search-input" :class="{'active':focusActive}">
                        <i class="el-icon-search"></i>
                        <input type="text" v-model="text" @keydown.enter='search' placeholder="输入关键词"
                               @focus="focusActive = true" @blur="focusActive = false">
                        <el-button type="text" size="mini" @click="search">查询</el-button>
                    </div>
                </div>
                <div class="right">
                    <el-menu :default-active="menuActive" class="el-menu-demo topMenu" mode="horizontal"
                             menu-trigger="click"
                             :router="true"
                    >
                        <el-menu-item index="/">首页</el-menu-item>
                        <el-menu-item index="/substation/create" :route="{path:'/substation/create'}">分站搭建
                        </el-menu-item>
                        <el-menu-item index="/task">任务大厅</el-menu-item>
                        <el-menu-item index="/promotion">推广返利</el-menu-item>
                        <el-menu-item index="/xxxx/xxxx" disabled>
                            <a :href="qqKf" target="_blank">联系我们</a>
                        </el-menu-item>

                    </el-menu>
                    <el-dropdown :hide-on-click="false" class="user">
                    <span class="el-dropdown-link">
                        <img :src="user.touxiang" alt="">
                        <span>{{user.nicheng}}</span>
                    </span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item @click.native="$router.push({name:'manageCenter'})">
                                <i class="el-icon-setting"></i> 管理中心
                            </el-dropdown-item>
                            <el-dropdown-item @click.native="logOut"><i class="el-icon-circle-close"></i> 退出登录
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </el-header>

            <el-main class="main">
                <slot></slot>
            </el-main>

        </el-container>

    </el-container>
</template>

<script>
    import {mapGetters, mapMutations} from 'vuex'
    import account from '../router/account'
    import buyer from '../router/buyer'
    import finance from '../router/finance'
    import seller from '../router/seller'

    export default {
        name: 'container',
        components: {},
        data() {
            return {
                focusActive: false,
                activeIndex: "1",
                isCollapse: false,
                text: '',
                menu: [
                    {
                        name: '我的账户',
                        icon: 'el-icon-suitcase',
                        items: account.map(item => {
                            return {name: item.meta.title, path: item.path}
                        })
                    },
                    {
                        name: '我是买家',
                        icon: 'el-icon-goods',

                        items: buyer.map(item => {
                            return {name: item.meta.title, path: item.path, hide: item.meta.hide}
                        })
                    },
                    {
                        name: '财务管理',
                        icon: 'el-icon-s-order',

                        items: finance.map(item => {
                            return {name: item.meta.title, path: item.path}
                        })
                    },
                    {
                        name: '我是商家',
                        icon: 'el-icon-s-custom',
                        items: seller.map(item => {
                            return {name: item.meta.title, path: item.path}
                        })
                    },

                ],
            }
        },
        computed: {
            ...mapGetters(['menuActive', 'searchText', 'user', 'qqKf', 'subStation']),
        },
        watch: {
            '$route': function (to) {
                this.sellerTip();

            }
        },
        methods: {
            ...mapMutations(['SET_MENU', 'UPDATE_SEARCH_TEXT', 'SET_CLICK']),
            search() {
                this.$router.push({path: '/search', query: {key: this.text, t: Date.now()}});
                // alert(this.text)
            },
            updateMessage(e) {
                // this.UPDATE_SEARCH_TEXT(e.target.value);

            },
            collapse() {
                //  this.isCollapse = !this.isCollapse
            },
            logOut() {
                this.$axios.get(`/api/User/tuichu`)
                    .then(res => {
                        localStorage.removeItem('user');
                        this.$store.commit('SET_USER', null)
                        this.$router.push(`/login`);

                    })
            },
            sellerTip() {
                if (!this.$store.state.isSeller && this.$route.path.includes('seller')) {
                    console.log(this.$store.state.isSeller)
                    this.$confirm('您还未开通商户功能，是否开通?', '提示', {
                        confirmButtonText: '去开通',
                        cancelButtonText: '取消',
                        closeOnClickModal: false,
                        closeOnPressEscape: false,
                        type: 'warning'
                    }).then(() => {
                        this.$router.push({name: 'manageCenter'})
                    }).catch(() => {
                        this.$router.go(-1);
                    });

                }
            }
        },
        created() {
            this.sellerTip();
        },
    }
</script>
<style>
    .el-menu-vertical-demo:not(.el-menu--collapse) {
        width: 200px;
        min-height: 400px;
    }
</style>
<style lang="less" scoped>
    .left-side {
        height: 100vh;
        background-color: #fff;
        border: 1px solid #eee;

        .logo {
            height: 60px;
            display: flex;
            align-items: center;
            border-right: solid 1px #e6e6e6;
            cursor: pointer;

            img {
                width: 120px;
                margin: 0 auto;
                display: block;
            }
        }

        .aside {
            display: flex;
            flex-direction: column;
            box-sizing: border-box;

        }

        .el-menu-vertical-demo {

        }

        /deep/ .el-menu {
            flex: 1;
            box-sizing: border-box;

            .is-active {
                .el-submenu__title {
                    background-color: #f0f5ff;
                    color: #409eff;
                    font-size: 14px;
                    font-weight: bold;
                    border-left: 5px solid;

                    i {
                        color: #409eff;
                    }
                }

                ul {
                    .is-active {
                        font-size: 14px;
                        font-weight: bold;
                    }
                }
            }
        }

        .header {
            text-align: right;
            font-size: 12px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .left {
                padding: 5px 10px;
                border-radius: 40px;
                background-color: #f3f6ff;

                .search-input {
                    i {
                        color: #409eff;
                        margin-right: 8px;
                    }

                    input {
                        border: none;
                        color: #a2a9ba;
                        outline: none;
                        background-color: #f3f6ff;

                        &::placeholder {
                            color: #a2a9ba;
                        }

                        width: 100px;
                        height: 22px;
                        transition: all .5s;
                    }

                    &.active {
                        input {
                            width: 220px;
                        }
                    }
                }

            }

            .right {
                display: flex;
                align-items: center;

                .user {
                    margin-left: 20px;

                    /deep/ .el-dropdown-link {
                        display: flex;
                        align-items: center;

                        img {
                            width: 45px;
                            height: 45px;
                            border-radius: 50%;
                            border: 1px solid #eee;
                            object-fit: cover;
                        }

                        span {
                            font-weight: 500;
                            font-size: 14px;
                            margin-left: 8px;
                            color: #3368fc;
                        }
                    }

                }

                .is-disabled {
                    opacity: 1;
                    cursor: pointer;

                    a {
                        line-height: 4.5;
                        display: inline-block;
                    }
                }
            }
        }

        .main {
            position: relative;
        }
    }

    .modal {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        background: #000;
        z-index: 99;
        opacity: .3;
    }

    .tip {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        color: #fff;
        font-size: 20px;
        margin-bottom: 20%;
    }
</style>